<template>
	<view>
		<div>
			<navitop>
				<i class="iconfont icon-jiantou-copy" slot="left-slot" @click="outlot"></i>
				<span slot="center-slot">
					<h4>{{titles}}</h4>
				</span>
				<i slot="right-slot">
					<!-- <i class="iconfont icon-sousuo1" style="font-size: 25px;padding-left: 15px;" ></i> -->
					<i class="iconfont icon-youcecaidan" style="font-size: 25px;padding-left: 15px;"
						@click="class_sort"></i>
				</i>
			</navitop>
		</div>
		<div :style="'padding-top:' + nv_height">
			<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
				:down="downOption" :up="upOption">
				<!-- 列表 -->
				
				<!-- 请购单 -->
				<purchaseList :dataSorce="dataSorce" :urlcode="curl_data.code" v-if="curl_data.code == 'PurchaseRequisition'"></purchaseList>
				
				<!-- 采购订单 -->
				<purchaseorderList :dataSorce="dataSorce" :urlcode="curl_data.code" v-if="curl_data.code == 'PurchaseOrder'"></purchaseorderList>
				
				<!-- 到货通知单 -->
				<arrivalList :dataSorce="dataSorce" :urlcode="curl_data.code" v-if="curl_data.code == 'PuArrival' && curl_data.sort == 0 "></arrivalList>
				
				<!-- 拒收通知单 -->
				<rejectionList :dataSorce="dataSorce" :urlcode="curl_data.code" v-if="curl_data.code == 'PuArrival' && curl_data.sort == 97 "></rejectionList>
				
				<!-- 采购入库单 -->
				<warehousingList :dataSorce="dataSorce" :urlcode="curl_data.code" v-if="curl_data.code == 'PurchaseReceiveVoucher' && curl_data.sort == 0 "></warehousingList>
				
				<!-- 采购退货单 -->
				<warehousingreturnList :dataSorce="dataSorce" :urlcode="curl_data.code" v-if="curl_data.code == 'PurchaseReceiveVoucher' && curl_data.sort == 99 "></warehousingreturnList>
				
				<!-- 采购发票 -->
				<invoiceList :dataSorce="dataSorce" :urlcode="curl_data.code" v-if="curl_data.code == 'PurchaseInvoice'"></invoiceList>	
				
				
				<div class="null_title" v-if="dataSorce == ''">
					<div>
						<i class="iconfont icon-empty iconcize"></i>
					</div>
					<div class="null_title_tow">
						没有更多数据
					</div>
				</div>
			</mescroll-body>
		</div>
		
		
		<!-- 气泡弹窗 -->
		<chunLei-popups v-model="value" :popData="datas" @tapPopup="bubble" :x="345" :y="95" placement="top-end">
		</chunLei-popups>
	</view>
</template>

<script>
import navitop from '@/components/common/navi-top'
import purchaseList from '@/pages/common/index/procure/purchase/purchase-list'
import purchaseorderList from '@/pages/common/index/procure/purchaseorder/purchase-list'
import arrivalList from '@/pages/common/index/procure/arrival/purchase-list'
import rejectionList from '@/pages/common/index/procure/rejection/purchase-list'
import warehousingList from '@/pages/common/index/procure/warehousing/purchase-list'
import warehousingreturnList from '@/pages/common/index/procure/warehousingreturn/purchase-list'
import invoiceList from '@/pages/common/index/procure/invoice/purchase-list'
import {vouPage,voucherDesign} from '@/common/api/procure/procureapi.js'
import chunLeiPopups from "@/components/chunLei-popups/chunLei-popups";
import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
export default {
	components:{
		navitop,
		chunLeiPopups,
		purchaseList,
		purchaseorderList,
		arrivalList,
		rejectionList,
		warehousingList,
		warehousingreturnList,
		invoiceList
	},
	mixins: [MescrollMixin],
	data(){
		return {
			titles: '111',
			value: false,
			nv_height: '',	// 设置顶部距离
			dataSorce: [],
			datas: [{
				title: '添加',
				code: 'billadd',
				icon: 'icon-tubiao_tianjia'
			}],
			curl_data: {},
			
			// 下拉刷新的配置
			downOption: {
				auto: false,
				beforeEndDelay: 300
			},
			// 上拉加载的配置
			upOption: {
				auto: false,
				page: {
					size: 10 // 每页数据的数量,默认10
				},
				noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
				empty: {
					use: true,
					tip: '暂无相关数据'
				},
				textNoMore: '没有更多数据了...',
				toTop: {
					offset: 1000 // 滚动多少才显示to-top 
				}
			},
			pages: 1
		}
	},
	onLoad(option) {
		this.titles = option.title;
		// 统一获取url参数
		this.curl_data = option;
	},
	mounted() {
		
		this.nv_height = uni.getSystemInfoSync().statusBarHeight + 60 + 'px';
		
		// 接口统一入口
		this.http_list();
	},
	methods: {
		class_sort(){
			this.value = !this.value;
		},
		outlot(){
			uni.switchTab({
				url: '/pages/index/index'
			})
		},
		
		// 跳转
		bubble(val){
			if(this.curl_data.code == 'PurchaseRequisition'){
				uni.navigateTo({
					url: '/pages/common/index/procure/purchase/purchase-add?title=' + this.curl_data.title + '&code=' + this.curl_data.code
				})
			}
			// 采购订单
			if(this.curl_data.code == 'PurchaseOrder'){
				uni.navigateTo({
					url: '/pages/common/index/procure/purchaseorder/purchase-add?title=' + this.curl_data.title + '&code=' + this.curl_data.code
				})
			}
			
			// 拒收通知单
			if(this.curl_data.code == 'PuArrival' && this.curl_data.sort == 97 ){
				uni.navigateTo({
					url: '/pages/common/index/procure/rejection/purchase-add?title=' + this.curl_data.title + '&code=' + this.curl_data.code
				})
			}
			
			// 到货通知单
			if(this.curl_data.code == 'PuArrival' && this.curl_data.sort == 0 ){
				uni.navigateTo({
					url: '/pages/common/index/procure/arrival/purchase-add?title=' + this.curl_data.title + '&code=' + this.curl_data.code
				})
			}
			
			// 采购入库单
			if(this.curl_data.code == 'PurchaseReceiveVoucher' && this.curl_data.sort == 0 ){
				uni.navigateTo({
					url: '/pages/common/index/procure/warehousing/purchase-add?title=' + this.curl_data.title + '&code=' + this.curl_data.code
				})
			}
			
			// 采购退库单
			if(this.curl_data.code == 'PurchaseReceiveVoucher' && this.curl_data.sort == 99 ){
				uni.navigateTo({
					url: '/pages/common/index/procure/warehousingreturn/purchase-add?title=' + this.curl_data.title + '&code=' + this.curl_data.code
				})
			}
			
			// 采购发票
			if( this.curl_data.code == 'PurchaseInvoice' ){
				uni.navigateTo({
					url: '/pages/common/index/procure/invoice/purchase-add?title=' + this.curl_data.title + '&code=' + this.curl_data.code
				})
			}
		},
		
		
		
		// 获取列表
		http_list(){
			this.lise_field();
		},
		
		// 获取表自定义列表
		lise_field(){
			voucherDesign({source:this.curl_data.code}).then(item => {
				if(item.code == 200){
					this.data_list(item.data)
				}
			})
		},
		
		// 获取数据列表
		data_list(val){
			
			let _this = this;
			vouPage({designSearchDtos:val,isSearchDetail: false,page: {current: this.pages, size: 10},someBusinessType: this.curl_data.sort}).then(item => {
				if(item.code == 200){
					// this.dataSorce = item.data.records;
					
					if(this.pages == 1){
						this.dataSorce = item.data.records;
					}else{
						item.data.records.filter(function (item){
							_this.dataSorce.push(item)
						})
					}
				}
			})
		},
		
		/*下拉刷新的回调*/
		downCallback(val) {
			console.log('下拉--------')
			this.lise_field();
			// 下拉刷新和上拉加载调同样的接口,直接mescroll.resetUpScroll()即可
			setTimeout(() => {
				this.mescroll.endSuccess();
			}, 500)
		},
		
		// 上拉加载
		upCallback(page) {
			console.log('上拉--------')
			this.pages++;
			// let obj = {
			// 	current: page.num, // 页码, 默认1
			// 	size: page.size, // 页长, 默认10条
			// };
			this.lise_field();
			setTimeout(()=>{
				this.mescroll.endErr();
			},500)
		},
		
	}
}

	
</script>

<style scoped lang="scss">

</style>
